package com.ncst.backend.service.impl;

import com.ncst.backend.domain.DrugInfo;
import com.ncst.backend.mapper.DrugInfoMapper;
import com.ncst.backend.service.DrugInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 药品信息服务实现类
 */
@Slf4j
@Service
public class DrugInfoServiceImpl implements DrugInfoService {

    @Autowired
    private DrugInfoMapper drugInfoMapper;

    @Override
    public DrugInfo getById(Integer id) {
        return drugInfoMapper.selectById(id);
    }

    @Override
    public List<DrugInfo> getAll() {
        return drugInfoMapper.selectAll();
    }

    @Override
    public List<DrugInfo> getByCondition(DrugInfo drugInfo) {
        return drugInfoMapper.selectByCondition(drugInfo);
    }

    @Override
    public List<DrugInfo> getByPage(Integer pageNum, Integer pageSize) {
        Integer offset = (pageNum - 1) * pageSize;
        return drugInfoMapper.selectByPage(offset, pageSize);
    }

    @Override
    public Long countAll() {
        return drugInfoMapper.countAll();
    }

    @Override
    public Long countByCondition(DrugInfo drugInfo) {
        return drugInfoMapper.countByCondition(drugInfo);
    }

    @Override
    public boolean save(DrugInfo drugInfo) {
        return drugInfoMapper.insert(drugInfo) > 0;
    }

    @Override
    public boolean saveBatch(List<DrugInfo> list) {
        return drugInfoMapper.insertBatch(list) > 0;
    }

    @Override
    public boolean updateById(DrugInfo drugInfo) {
        return drugInfoMapper.updateById(drugInfo) > 0;
    }

    @Override
    public boolean removeById(Integer id) {
        return drugInfoMapper.deleteById(id) > 0;
    }

    @Override
    public boolean removeByIds(List<Integer> ids) {
        return drugInfoMapper.deleteByIds(ids) > 0;
    }
}
